package com.cloud.pole.shop.biz.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.mapper.order.ShopOrderPayMapper;
import com.cloud.pole.shop.model.entity.order.ShopOrderPay;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-08 16:23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ShopOrderPayBiz extends BaseBiz<ShopOrderPayMapper, ShopOrderPay> {
	
	@Autowired
	private ShopOrderPayMapper shopOrderPayMapper;
	
	
	public ShopOrderPay selectByPrimaryKey(Long payId) {
		return mapper.selectByPrimaryKey(payId);
	}
	
	/**
	 * 根据订单id获取支付id
	 * @param orderSns
	 * @return
	 */
	public ShopOrderPay selectByOrderSn(String orderSns) {
		ShopOrderPay shopOrderPay = new ShopOrderPay();
		shopOrderPay.setOrderSnS(orderSns);
		return mapper.selectOne(shopOrderPay);
	}
	
	/**
	 * 根据订单id获取支付id
	 * @param orderSns
	 * @return
	 */
	public ShopOrderPay selectByPgOrderSn(String pgOrderSns) {
		ShopOrderPay shopOrderPay = new ShopOrderPay();
		shopOrderPay.setPgOrderSn(pgOrderSns);
		return mapper.selectOne(shopOrderPay);
	}
	
	/**
	 * 根据订单号删除，|111111111111111111111111||222222222222222222222222|'
	 * @param orderSn
	 */
	public int deleteByOrderSn(String orderSn) {
		Example example = new Example(ShopOrderPay.class);
		Criteria criteria = example.createCriteria();
		criteria.andLike("orderSnS", "%" + orderSn + "%");
		return mapper.deleteByExample(example);
    }
	
	/**
	 * 添加返回值
	 * @param entity
	 */
    public void insertUseGeneratedKeys(ShopOrderPay entity) {
    	shopOrderPayMapper.insertUseGeneratedKeys(entity);
    }
    
    @Override
    public void updateSelectiveById(ShopOrderPay entity) {
    	super.updateSelectiveById(entity);
    }
	
}
